<?php
namespace app\common\model;

use think\Db;
use think\Model;

class Qudaoduanxin extends Model
{
    public function getStatusTextAttr($value,$data)
    {
        $status = [1=>'<span class="label label-success">启用</span>',2=>'<span class="label label-danger">禁用'];
        return $status[$data['status']];
    }
    public function getYiyuanTextAttr($value,$data){
        $status =  Db::name('leibie')->where('leibie',3)->cache(true,360)->column(['id','name']);
        return $status[$data['yiyuan']];
    }
    public function getKechengTextAttr($value,$data){
        $status =  Db::name('leibie')->where('leibie',9)->cache(true,360)->column(['id','name']);
        return $status[$data['kecheng']];
    }
    public  function map($data){
        //ID
        if(!empty($data['id'])){
            trim($data['id']);
            $map['id']=['eq',$data['id']];
        }
        //医院
        if(!empty($data['yiyuan'])){
            trim($data['yiyuan']);
            $map['yiyuan']=['eq',$data['yiyuan']];
        }
        //课程
        if(!empty($data['kecheng'])){
            trim($data['kecheng']);
            $map['kecheng']=['eq',$data['kecheng']];
        }
        $map['status'] = 1;//开启的订单
        return $map;
    }
    public function Yiyuan(){
        $status =  Db::name('leibie')->where('leibie',3)->cache(true,360)->select();
        return $status;
    }
    public function Kecheng(){
        $status =  Db::name('leibie')->where('leibie',9)->cache(true,360)->select();
        return $status;
    }
    //修改
    public function edit($data){
        //新建
        if(empty($data['id'])){
            $res = $this->save($data);
            //成功，更新日志
            if($res){
                return ['status'=>'1','msg'=>"新增成功",'url'=>url('index')];
            }else{//失败
                return ['status'=>'0','msg'=>$this->getError()];
            }
        }else{//更新

            $res = $this->isUpdate()->save($data);
            //成功
            if($res){
                return ['status'=>'1','msg'=>'数据更新成功！','url'=>url('index')];
            }else{//失败
                return ['status'=>'0','msg'=>$this->getError()];
            }
        }
    }
}

?>